local skel = fk.CreateSkill{
  name = "#rmt_blade_skill",
  attached_equip = "rmt_blade",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["#rmt_blade_skill"] = "破邪偃月刀",
  ["@@rmt_blade"] = "破邪:封技能",
}

skel:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/standard_cards/audio/card/blade")
    room:setEmotion(player, "./packages/standard_cards/image/anim/blade")
    room:addPlayerMark(data.to, "@@rmt_blade")
    data.extra_data = data.extra_data or {}
    data.extra_data.rmt_blade = data.extra_data.rmt_blade or {}
    data.extra_data.rmt_blade[tostring(data.to.id)] = (data.extra_data.rmt_blade[tostring(data.to.id)] or 0) + 1
  end,
})

skel:addEffect(fk.CardUseFinished, {
  can_refresh = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.rmt_blade
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for key, num in pairs(data.extra_data.rmt_blade) do
      local p = room:getPlayerById(tonumber(key))
      if p and p:getMark("@@rmt_blade") > 0 then
        room:removePlayerMark(p, "@@rmt_blade", num)
      end
    end
    data.extra_data.rmt_blade = nil
  end,
})

skel:addEffect("invalidity", {
  invalidity_func = function(self, player, skill)
    return player:getMark("@@rmt_blade") ~= 0 and skill:isPlayerSkill(player)
  end,
})

return skel
